<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>个人信息</title>
	<meta name="renderer" content="webkit">	
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
	<meta name="apple-mobile-web-app-status-bar-style" content="black">	
	<meta name="apple-mobile-web-app-capable" content="yes">	
	<meta name="format-detection" content="telephone=no">	
	<link rel="stylesheet" type="text/css" th:href="@{common/layui/css/layui.css}" href="common/layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{common/bootstrap/css/bootstrap.css}" href="common/bootstrap/css/bootstrap.css" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{common/global.css}" href="common/global.css" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{css/personal.css}" href="css/personal.css" media="all">
</head>
<body>
<section class="layui-larry-box">
	<div class="larry-personal">
		<header class="larry-personal-tit">
			<span>个人信息</span>
		</header><!-- /header -->
		<div class="larry-personal-body clearfix">
			<form class="layui-form col-lg-5" th:id="infoform" th:action="@{/user/update}" action="" method="post">
				<div hidden="hidden"><input name="uId" th:value="${session.loginUser.uId}"></div>
				<div class="layui-form-item">
					<label class="layui-form-label">用户名</label>
					<div class="layui-input-block">  
						<input type="text" name="username"  autocomplete="off"  class="layui-input layui-disabled" th:value="${session.loginUser.username}" value="admin" disabled="disabled" >
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">所属角色</label>
					<div class="layui-input-block">
						<input type="text" name="title"  autocomplete="off" class="layui-input layui-disabled" value="超级管理员" disabled="disabled">
					</div>
				</div>
				<!--<div class="layui-form-item">-->
					<!--<label class="layui-form-label">真实姓名</label>-->
					<!--<div class="layui-input-block">-->
						<!--<input type="text" name="username"  autocomplete="off" class="layui-input" value="Larry">-->
					<!--</div>-->
				<!--</div>-->
				<div class="layui-form-item">
					<label class="layui-form-label">手机号码</label>
					<div class="layui-input-block">
						<input type="text" name="phone"  autocomplete="off" class="layui-input" th:value="${session.loginUser.phone}" th:placeholder="${session.loginUser.phone}" placeholder="输入手机号码">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">邮箱</label>
					<div class="layui-input-block">
						<input type="text" name="email"  autocomplete="off" class="layui-input" th:value="${session.loginUser.email}" th:placeholder="${session.loginUser.email}" placeholder="输入手机号码">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">性别</label>
					<div class="layui-input-block">
						<input type="radio" name="gender"  value="0" title="男" checked=""><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><span>男</span></div>
						<input type="radio" name="gender" value="1" title="女"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><span>女</span></div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">错题数/总题数</label>
					<div class="layui-input-block">
						<input type="text" name="errorByall"  autocomplete="off" class="layui-input layui-disabled"
							   th:value="${session.loginUser.allquestioncount} == 0 ? '您当前还未刷题' : ${session.loginUser.errorquestioncount} + ' / ' + ${session.loginUser.allquestioncount} + ' = ' + ${session.loginUser.errorquestioncount}/${session.loginUser.allquestioncount}" disabled="disabled">
					</div>
				</div>
				<!--<div class="layui-form-item">-->
					<!--<label class="layui-form-label">修改头像</label>-->
					<!--<div class="layui-input-block">-->
						<!--<input type="file" name="file" class="layui-upload-file">-->
					<!--</div>-->
				<!--</div>-->
				<div class="layui-form-item">
					<label class="layui-form-label">界面语言</label>
					<div class="layui-input-block">
						<select name="interest" lay-filter="aihao">
							<option value=""></option>
							<option value="0" selected="selected">中文</option>
							<option value="1">英文(尚未进行国际化)</option>
						</select>
					</div>
				</div>

				<!--<div class="layui-form-item layui-form-text">-->
					<!--<label class="layui-form-label">座右铭</label>-->
					<!--<div class="layui-input-block">-->
						<!--<textarea placeholder="既然选择了远方，便只顾风雨兼程；路漫漫其修远兮，吾将上下而求索" value="" class="layui-textarea"></textarea>-->
					<!--</div>-->
				<!--</div>-->
				<!---->
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button id="submit" type="button" class="layui-btn" onsubmit="false" lay-submit="" lay-filter="demo1">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</section>
<script type="text/javascript" th:src="@{/easyui/jquery-1.8.0.min.js}"></script>
<link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/default/easyui.css}">
<link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/icon.css}">
<script type="text/javascript" th:src="@{/easyui/jquery.easyui.min.js}"></script>
<script type="text/javascript" th:src="@{common/layui/layui.js}" src="common/layui/layui.js"></script>
<script type="text/javascript">
	layui.use(['form','upload'],function(){
         var form = layui.form();
         layui.upload({ 
             url: '' ,//上传接口 
             success: function(res){
              //上传成功后的回调 
              console.log(res) 
            } 
         });

	});

    $(function () {
        //绑定提交按钮
        $("#submit").click(function () {
            var email = $(" input[ name='email' ] ").val().trim();
            var phone = $(" input[ name='phone' ] ").val().trim();

            //2，定义正则
            var reg_email = /^\w+@\w+\.\w+$/;
            //3，判断
            var flag_email = reg_email.test(email);

            var reg_phone = /^1[34578]\d{9}$/;

            var flag_phone = reg_phone.test(phone);

            if(flag_email == true && flag_phone == true) {
                var targetUrl = $("#infoform").attr("action");
                var data = $("#infoform").serialize();

                $.ajax({
                    type:'post',
                    url:targetUrl,
                    cache: false,
                    data:data,  //重点必须为一个变量如：data
                    dataType:'json',
                    success:function(data){
                        // alert("zzz");
                        if(data == 1) {
                            // window.location.reload();
                            $.messager.alert("提示","更新成功","info");
                            // window.location.href="/index";
                        }

                        if(data == 0) {
                            //alert("更新失败");
                            $.messager.alert("提示","更新失败","error");
                        }

                        if(data == 2) {
                            //alert("更新失败");
                            $.messager.alert("提示","邮箱或电话格式错误","error");
                        }

                    },
                    error:function(){
                        $.messager.alert("提示","请求失败","error");
                    }
                })
			}else  {
                if(flag_email == false) {
                    $.messager.alert("提示","邮箱格式错误","error");

                }
                if(flag_phone == false) {
                    $.messager.alert("提示","电话格式错误","error");
				}
			}

        });
    });

</script>
</body>
</html>